package com.woniuxy.portal.controller;

import com.woniuxy.portal.model.entity.BookType;
import com.woniuxy.portal.service.BookTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin(origins = "*")
@Api(tags = "图书类别接口")
@RestController
@RequestMapping("/bookType")
public class BookTypeController {

    private final BookTypeService bookTypeService;

    @Autowired
    public BookTypeController(BookTypeService bookTypeService) {
        this.bookTypeService = bookTypeService;
    }

    /**
     * 查询所有图书类别
     *
     * @return ResponseEntity<List < BookType>> 包含所有图书类别的响应实体
     */
    @ApiOperation("首页：查询所有图书类别")
    @GetMapping("/findAllType")
    public ResponseEntity<List<BookType>> findAllType() {
        // 调用服务层查询所有图书类别
        List<BookType> bookTypes = bookTypeService.findAllType();
        // 返回包含图书类别列表的成功响应
        return ResponseEntity.ok(bookTypes);
    }

}
